package com.example.system.service;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.RandomUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.example.system.dto.UserDto;
import com.example.system.dto.UserInfo;
import com.example.system.dto.UserParam;
import com.example.system.dto.WeixinExtraDto;
import com.example.system.entity.User;
import com.example.system.entity.WeixinExtra;
import com.example.system.vo.UserVo;
import org.springframework.data.domain.Pageable;


/**
 * @author 王令
 * @since 2022-08-05
 */
public interface IUserService extends IService<User> {

    void create(UserDto userDto);

    void update(UserDto userDto);

    UserInfo findUserInfoByUser(User user);

    UserInfo findUserInfoByUsername(String username);

    WeixinExtraDto findWeixinExtra(String username);

    Page<UserVo> listWithPagination(Pageable pageable, UserParam param);

    UserVo findUserVoById(Long id);

    default String nextUid() {
        long seconds = DateUtil.currentSeconds();
        while (ObjectUtil.isNotNull(this.getOne(
                Wrappers.<User>lambdaQuery().select(User::getId).eq(User::getUsername, String.valueOf(seconds))))) {
            // 2001-09-09 09:46:40 ~ 2022-12-13 10:39:42
            seconds = RandomUtil.randomLong(1000000000L, 1670899182L);
        }
        return String.valueOf(seconds);
    }

    void saveWeixinExtra(WeixinExtra extra);

}
